﻿/*----------------------------------------------------------------
// Copyright (C) 2014 苏州麦迪斯顿医疗科技股份有限公司
// 文件名：ExceptionHandlingBehaviourAttribute.cs
// 文件功能描述：ExceptionHandlingBehaviourAttribute
// 创建标识：顾伟伟-2014-04-03
----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel;
using System.Threading;
using System.Web.Security;

namespace CPOE.Framework.ExceptionHanding
{
    /// <summary>
    /// 护展WCF的服务行为,支持异常处理
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class ExceptionHandlingBehaviorAttribute : Attribute, IServiceBehavior
    {
        public ExceptionHandlingBehaviorAttribute()
        {
          
        }

        public void AddBindingParameters(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {

        }

        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            foreach (ChannelDispatcher channdlDispatcher in serviceHostBase.ChannelDispatchers)
            {
                if (channdlDispatcher.IncludeExceptionDetailInFaults == false)
                    channdlDispatcher.ErrorHandlers.Add(new FaultExceptionHandler());
            }
        }
      
        public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
           
        }
    }
}
